package org.jeecg.modules.system.util;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;

import java.util.concurrent.ConcurrentHashMap;

public class SystemUtils {
    private static final ConcurrentHashMap<String, Boolean> MAP = new ConcurrentHashMap<>();
    private static final ThreadLocal<String> THREADLOCAL = new ThreadLocal();

    public static Boolean checkMethod() {
        //不需要拦截返回true
        return MAP.containsKey(THREADLOCAL.get());
    }

    public static void addNoQueryInterceptorMethod(String methodStr) {
        MAP.put(methodStr, true);
    }

    public static void putCurrentMethod(String methodStr) {
        THREADLOCAL.set(methodStr);
    }

    public static String getCUserSOrgCode() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String orgCode = sysUser.getOrgCode();
        char[] chars = orgCode.toCharArray();
        int e = chars.length;
        for (int i = 1; i < chars.length; i++) {
            char aChar = chars[i];
            if (aChar == 'A') {
                e = i;
                break;
            }
        }
        return orgCode.substring(0, e);
    }
}
